package com.foundersoftware.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.foundersoftware.component.IComponentParseExcel;
import com.foundersoftware.component.impl.ComponentParseExcel;
import com.foundersoftware.model.Employee;

public class EmployeeServlet extends HttpServlet {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

 
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		List<Object> exportData = addEmployee();
		IComponentParseExcel parserExcel = new ComponentParseExcel();
		parserExcel.exportExcel(exportData, "Template.xls",getServletContext());
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
	
	private List<Object> addEmployee(){
		List<Object> employees = new ArrayList<Object>();
		
		for (int i = 0; i < 100; i++) {
			Employee employee = new Employee();
			employee.setName("Colin - "+i);
			employee.setAge(i+10);
			employee.setCity("Bei - Jing - "+ i);
			employee.setDepartment("N - A - T "+i);
			employees.add(employee);
		}
		
		return employees;
	}
}
